package com.leyou.auth.web;

import com.leyou.auth.constants.JwtConstants;
import com.leyou.auth.service.userAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserAuthController {
    @Autowired
    private userAuthService userAuthService;

    /**todo
     * 用户登录
     * @param username 用户名
     * @param password 密码
     * @return 无
     */
    @PostMapping("/login")
    public ResponseEntity<Void> login(@RequestParam("username")String username, @RequestParam("password")String password, HttpServletResponse response){
        userAuthService.login(username,password,response);
        return ResponseEntity.ok().build();
    }
    /**
     * 退出登陆
     */
    @PostMapping("/logout")
    public ResponseEntity<Void> logout(@CookieValue(JwtConstants.COOKIE_NAME)String token,HttpServletResponse response){
        userAuthService.logout(token,response);
        return ResponseEntity.ok().build();
    }
}
